#include <arrow_fill_cc.h>
#include <stdio.h>
#include <stdlib.h> 

extern "C" {
    #include <arrow_fill_c.h>
}

struct CgoArrowArray GoFillInts(int withNulls) {
    printf("C GoFillInts withNulls = %d \n", withNulls > 0);

    CxxArrowArray array = cxx_fill_ints(withNulls > 0);

    {
        printf("---------------C print-----------------\n");

        if(array.null_bitmap!=NULLPTR) {
        printf("null_bitmap: length=%ld\n", array.len_null_bitmap);
        printf("null_bitmap:  十进制 [");
        for(int i =0; i < array.len_null_bitmap; i++) {
        //   char s[10];
        //   itoa(array.null_bitmap[i], s, 2);
        //   printf("%s ", s); 
            // %o 八进制
            printf("%d ", array.null_bitmap[i]);
        }
        printf("]\n");
        printf("address: %p\n", array.null_bitmap);
        }
        printf("data: length=%ld\n", array.len_data);
        printf("data:  十进制 [");
        for(int i =0; i < array.len_data; i++) {
        //   char s[10];
        //   itoa(array.data[i], s, 2);
        //   printf("%s ", s);
            printf("%d ", array.data[i]);
        }
        printf("]\n");
        printf("address: %p\n", array.data);
    }

    return CgoArrowArray{
        array.len_null_bitmap,
        array.null_bitmap,
        array.len_data,
        array.data,
        array.rows,
        array.type
    };
}

void freeHolder() {
    printf("-----------------------------------C freeHolder----------------------------\n");
    freeArrayPointer();
}

int GoAddInts(int a, int b) {
    printf("C GoAddInts: %d + %d=?\n", a, b);
    return a + b;
} 
